<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="每日任务ID" prop="dailyTaskId">
        <el-input
          v-model="queryParams.dailyTaskId"
          placeholder="请输入每日任务ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="面试题编号" prop="interviewId">
        <el-input
          v-model="queryParams.interviewId"
          placeholder="请输入面试题编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="日期" prop="date">
        <el-date-picker clearable
          v-model="queryParams.date"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="班级id" prop="classesId">
        <el-input
          v-model="queryParams.classesId"
          placeholder="请输入班级id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学生ID" prop="studentId">
        <el-input
          v-model="queryParams.studentId"
          placeholder="请输入学生ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="得分" prop="score">
        <el-input
          v-model="queryParams.score"
          placeholder="请输入得分"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="粘贴数" prop="pasteCount">
        <el-input
          v-model="queryParams.pasteCount"
          placeholder="请输入粘贴数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手写数" prop="writeCount">
        <el-input
          v-model="queryParams.writeCount"
          placeholder="请输入手写数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="删除数" prop="deleteCount">
        <el-input
          v-model="queryParams.deleteCount"
          placeholder="请输入删除数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手写率" prop="handwritingRate">
        <el-input
          v-model="queryParams.handwritingRate"
          placeholder="请输入手写率"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="粘贴率" prop="pasteRate">
        <el-input
          v-model="queryParams.pasteRate"
          placeholder="请输入粘贴率"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['teaching:daily_tasks_record:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['teaching:daily_tasks_record:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['teaching:daily_tasks_record:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['teaching:daily_tasks_record:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="daily_tasks_recordList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="id" />
      <el-table-column label="每日任务ID" align="center" prop="dailyTaskId" />
      <el-table-column label="面试题编号" align="center" prop="interviewId" />
      <el-table-column label="难点" align="center" prop="difficulty" />
      <el-table-column label="答案" align="center" prop="answer" />
      <el-table-column label="日期" align="center" prop="date" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.date, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是什么" align="center" prop="what" />
      <el-table-column label="怎么用" align="center" prop="how" />
      <el-table-column label="有什么用" align="center" prop="why" />
      <el-table-column label="什么场景用" align="center" prop="ifThen" />
      <el-table-column label="班级id" align="center" prop="classesId" />
      <el-table-column label="学生ID" align="center" prop="studentId" />
      <el-table-column label="得分" align="center" prop="score" />
      <el-table-column label="建议" align="center" prop="advance" />
      <el-table-column label="评价" align="center" prop="appraise" />
      <el-table-column label="粘贴数" align="center" prop="pasteCount" />
      <el-table-column label="手写数" align="center" prop="writeCount" />
      <el-table-column label="删除数" align="center" prop="deleteCount" />
      <el-table-column label="手写率" align="center" prop="handwritingRate" />
      <el-table-column label="粘贴率" align="center" prop="pasteRate" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['teaching:daily_tasks_record:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['teaching:daily_tasks_record:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改学生面试题练习记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="每日任务ID" prop="dailyTaskId">
          <el-input v-model="form.dailyTaskId" placeholder="请输入每日任务ID" />
        </el-form-item>
        <el-form-item label="面试题编号" prop="interviewId">
          <el-input v-model="form.interviewId" placeholder="请输入面试题编号" />
        </el-form-item>
        <el-form-item label="难点" prop="difficulty">
          <el-input v-model="form.difficulty" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="答案" prop="answer">
          <el-input v-model="form.answer" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="日期" prop="date">
          <el-date-picker clearable
            v-model="form.date"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="是什么" prop="what">
          <el-input v-model="form.what" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="怎么用" prop="how">
          <el-input v-model="form.how" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="有什么用" prop="why">
          <el-input v-model="form.why" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="什么场景用" prop="ifThen">
          <el-input v-model="form.ifThen" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="班级id" prop="classesId">
          <el-input v-model="form.classesId" placeholder="请输入班级id" />
        </el-form-item>
        <el-form-item label="学生ID" prop="studentId">
          <el-input v-model="form.studentId" placeholder="请输入学生ID" />
        </el-form-item>
        <el-form-item label="得分" prop="score">
          <el-input v-model="form.score" placeholder="请输入得分" />
        </el-form-item>
        <el-form-item label="建议" prop="advance">
          <el-input v-model="form.advance" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="评价" prop="appraise">
          <el-input v-model="form.appraise" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="粘贴数" prop="pasteCount">
          <el-input v-model="form.pasteCount" placeholder="请输入粘贴数" />
        </el-form-item>
        <el-form-item label="手写数" prop="writeCount">
          <el-input v-model="form.writeCount" placeholder="请输入手写数" />
        </el-form-item>
        <el-form-item label="删除数" prop="deleteCount">
          <el-input v-model="form.deleteCount" placeholder="请输入删除数" />
        </el-form-item>
        <el-form-item label="手写率" prop="handwritingRate">
          <el-input v-model="form.handwritingRate" placeholder="请输入手写率" />
        </el-form-item>
        <el-form-item label="粘贴率" prop="pasteRate">
          <el-input v-model="form.pasteRate" placeholder="请输入粘贴率" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDaily_tasks_record, getDaily_tasks_record, delDaily_tasks_record, addDaily_tasks_record, updateDaily_tasks_record } from "@/api/teaching/daily_tasks_record";

export default {
  name: "Daily_tasks_record",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 学生面试题练习记录表格数据
      daily_tasks_recordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        dailyTaskId: null,
        interviewId: null,
        difficulty: null,
        answer: null,
        date: null,
        what: null,
        how: null,
        why: null,
        ifThen: null,
        classesId: null,
        studentId: null,
        score: null,
        advance: null,
        appraise: null,
        pasteCount: null,
        writeCount: null,
        deleteCount: null,
        handwritingRate: null,
        pasteRate: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        dailyTaskId: [
          { required: true, message: "每日任务ID不能为空", trigger: "blur" }
        ],
        interviewId: [
          { required: true, message: "面试题编号不能为空", trigger: "blur" }
        ],
        answer: [
          { required: true, message: "答案不能为空", trigger: "blur" }
        ],
        date: [
          { required: true, message: "日期不能为空", trigger: "blur" }
        ],
        classesId: [
          { required: true, message: "班级id不能为空", trigger: "blur" }
        ],
        studentId: [
          { required: true, message: "学生ID不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询学生面试题练习记录列表 */
    getList() {
      this.loading = true;
      listDaily_tasks_record(this.queryParams).then(response => {
        this.daily_tasks_recordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        dailyTaskId: null,
        interviewId: null,
        difficulty: null,
        answer: null,
        date: null,
        what: null,
        how: null,
        why: null,
        ifThen: null,
        classesId: null,
        studentId: null,
        score: null,
        advance: null,
        appraise: null,
        pasteCount: null,
        writeCount: null,
        deleteCount: null,
        handwritingRate: null,
        pasteRate: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加学生面试题练习记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getDaily_tasks_record(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改学生面试题练习记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDaily_tasks_record(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDaily_tasks_record(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除学生面试题练习记录编号为"' + ids + '"的数据项？').then(function() {
        return delDaily_tasks_record(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('teaching/daily_tasks_record/export', {
        ...this.queryParams
      }, `daily_tasks_record_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
